package leecode

func isSymmetric(root *TreeNode) bool {
	if root == nil {
		return true
	}
	return compare(root.Left, root.Right)
}

func compare(left *TreeNode, right *TreeNode) bool {
	if (left == nil && right != nil) || (left != nil && right == nil) {
		return false
	}
	if left == nil && right == nil {
		return true
	}
	if left.Val != right.Val {
		return false
	}
	//递归遍历左子树的左 , 右子树的右
	isEqureLeft := compare(left.Left, right.Right)
	//递归遍历左子树的右 , 右子树的左
	isEqureRight := compare(left.Right, right.Left)
	return isEqureLeft && isEqureRight
}
